<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD><TITLE>fontchooser manual page - Built-In Commands</TITLE>
<link rel="stylesheet" href="../docs.css" type="text/css" media="all">
</HEAD>
<BODY><H2><a href="../contents.htm">Tcl8.6.11/Tk8.6.11 Documentation</a> <small>&gt;</small> <a href="contents.htm">Tk Commands</a> <small>&gt;</small> fontchooser</H2>
<H3><A HREF="../UserCmd/contents.htm">Tcl/Tk Applications</A> | <A HREF="../TclCmd/contents.htm">Tcl Commands</A> | <A HREF="../TkCmd/contents.htm">Tk Commands</A> | <A HREF="../ItclCmd/contents.htm">[incr Tcl] Package Commands</A> | <A HREF="../SqliteCmd/contents.htm">SQLite3 Package Commands</A> | <A HREF="../TdbcCmd/contents.htm">TDBC Package Commands</A> | <A HREF="../TdbcmysqlCmd/contents.htm">tdbc::mysql Package Commands</A> | <A HREF="../TdbcodbcCmd/contents.htm">tdbc::odbc Package Commands</A> | <A HREF="../TdbcpostgresCmd/contents.htm">tdbc::postgres Package Commands</A> | <A HREF="../TdbcsqliteCmd/contents.htm">tdbc::sqlite3 Package Commands</A> | <A HREF="../ThreadCmd/contents.htm">Thread Package Commands</A> | <A HREF="../TclLib/contents.htm">Tcl C API</A> | <A HREF="../TkLib/contents.htm">Tk C API</A> | <A HREF="../ItclLib/contents.htm">[incr Tcl] Package C API</A> | <A HREF="../TdbcLib/contents.htm">TDBC Package C API</A></H3>
<DL>
<DD><A HREF="fontchooser.htm#M2" NAME="L722">NAME</A>
<DL><DD>fontchooser &mdash; control font selection dialog</DD></DL>
<DD><A HREF="fontchooser.htm#M3" NAME="L723">SYNOPSIS</A>
<DL>
</DL>
<DD><A HREF="fontchooser.htm#M4" NAME="L724">DESCRIPTION</A>
<DL class="description">
<DD><A HREF="fontchooser.htm#M5" NAME="L725"><B>tk fontchooser</B> <B>configure </B>?<I>-option value -option value ...</I>?</A>
<DD><A HREF="fontchooser.htm#M6" NAME="L726"><B>tk fontchooser</B> <B>show</B></A>
<DD><A HREF="fontchooser.htm#M7" NAME="L727"><B>tk fontchooser</B> <B>hide</B></A>
</DL>
<DD><A HREF="fontchooser.htm#M8" NAME="L728">CONFIGURATION OPTIONS</A>
<DL class="configuration options">
<DD><A HREF="fontchooser.htm#M9" NAME="L729"><B>-parent</B></A>
<DD><A HREF="fontchooser.htm#M10" NAME="L730"><B>-title</B></A>
<DD><A HREF="fontchooser.htm#M11" NAME="L731"><B>-font</B></A>
<DD><A HREF="fontchooser.htm#M12" NAME="L732"><B>-command</B></A>
<DD><A HREF="fontchooser.htm#M13" NAME="L733"><B>-visible</B></A>
</DL>
<DD><A HREF="fontchooser.htm#M14" NAME="L734">VIRTUAL EVENTS</A>
<DL class="virtual events">
<DD><A HREF="fontchooser.htm#M15" NAME="L735"><B>&lt;&lt;TkFontchooserVisibility&gt;&gt;</B></A>
<DD><A HREF="fontchooser.htm#M16" NAME="L736"><B>&lt;&lt;TkFontchooserFontChanged&gt;&gt;</B></A>
</DL>
<DD><A HREF="fontchooser.htm#M17" NAME="L737">NOTES</A>
<DD><A HREF="fontchooser.htm#M18" NAME="L738">EXAMPLE</A>
<DD><A HREF="fontchooser.htm#M19" NAME="L739">SEE ALSO</A>
<DD><A HREF="fontchooser.htm#M20" NAME="L740">KEYWORDS</A>
</DL>
<H3><A NAME="M2">NAME</A></H3>
fontchooser &mdash; control font selection dialog
<H3><A NAME="M3">SYNOPSIS</A></H3>
<B><A HREF="../TkCmd/tk.htm">tk fontchooser</A></B> <B>configure</B> ?<I>-option value -option value ...</I>?<BR>
<B><A HREF="../TkCmd/tk.htm">tk fontchooser</A></B> <B>show</B><BR>
<B><A HREF="../TkCmd/tk.htm">tk fontchooser</A></B> <B>hide</B><BR>
<H3><A NAME="M4">DESCRIPTION</A></H3>
The <B><A HREF="../TkCmd/tk.htm">tk fontchooser</A></B> command controls the Tk font selection dialog. It uses
the native platform font selection dialog where available, or a dialog
implemented in Tcl otherwise.
<P>
Unlike most of the other Tk dialog commands, <B><A HREF="../TkCmd/tk.htm">tk fontchooser</A></B> does not
return an immediate result, as on some platforms (Mac OS X) the standard font
dialog is modeless while on others (Windows) it is modal. To accommodate this
difference, all user interaction with the dialog will be communicated to the
caller via callbacks or virtual events.
<P>
The <B><A HREF="../TkCmd/tk.htm">tk fontchooser</A></B> command can have one of the following forms:
<P>
<DL class="description">
<DT><A NAME="M5"><B>tk fontchooser</B> <B>configure </B>?<I>-option value -option value ...</I>?</A><DD>
Set or query one or more of the configurations options below (analogous to Tk
widget configuration).
<P><DT><A NAME="M6"><B>tk fontchooser</B> <B>show</B></A><DD>
Show the font selection dialog. Depending on the platform, may return
immediately or only once the dialog has been withdrawn.
<P><DT><A NAME="M7"><B>tk fontchooser</B> <B>hide</B></A><DD>
Hide the font selection dialog if it is visible and cause any pending
<B><A HREF="../TkCmd/tk.htm">tk fontchooser</A></B> <B>show</B> command to return.
<P></DL>
<P>
<H3><A NAME="M8">CONFIGURATION OPTIONS</A></H3>
<DL class="configuration options">
<DT><A NAME="M9"><B>-parent</B></A><DD>
Specifies/returns the logical parent window of the font selection dialog
(similar to the <B>-parent</B> option to other dialogs). The font selection
dialog is hidden if it is visible when the parent window is destroyed.
<P><DT><A NAME="M10"><B>-title</B></A><DD>
Specifies/returns the title of the dialog. Has no effect on platforms where the
font selection dialog does not support titles.
<P><DT><A NAME="M11"><B>-font</B></A><DD>
Specifies/returns the font that is currently selected in the dialog if it is
visible, or that will be initially selected when the dialog is shown (if
supported by the platform). Can be set to the empty string to indicate that no
font should be selected. Fonts can be specified in any form given by the &quot;FONT
DESCRIPTION&quot; section in the <B><A HREF="../TkCmd/font.htm">font</A></B> manual page.
<P><DT><A NAME="M12"><B>-command</B></A><DD>
Specifies/returns the command prefix to be called when a font selection has
been made by the user. The command prefix is evaluated at the global level
after having the specification of the selected font appended. On platforms
where the font selection dialog offers the user control of further font
attributes (such as color), additional key/value pairs may be appended before
evaluation. Can be set to the empty string to indicate that no callback should
be invoked. Fonts are specified by a list of form [3] of the &quot;FONT DESCRIPTION&quot;
section in the <B><A HREF="../TkCmd/font.htm">font</A></B> manual page (i.e. a list of the form
<I>{family size style ?style ...?}</I>).
<P><DT><A NAME="M13"><B>-visible</B></A><DD>
Read-only option that returns a boolean indicating whether the font selection
dialog is currently visible. Attempting to set this option results in an error.

<P></DL>
<P>
<H3><A NAME="M14">VIRTUAL EVENTS</A></H3>
<DL class="virtual events">
<DT><A NAME="M15"><B>&lt;&lt;TkFontchooserVisibility&gt;&gt;</B></A><DD>
Sent to the dialog parent whenever the visibility of the font selection dialog
changes, both as a result of user action (e.g. disposing of the dialog via
OK/Cancel button or close box) and of the <B><A HREF="../TkCmd/tk.htm">tk fontchooser</A></B>
<B>show</B>/<B>hide</B> commands being called. Binding scripts can determine the
current visibility of the dialog by querying the <B>-visible</B> configuration
option.
<P><DT><A NAME="M16"><B>&lt;&lt;TkFontchooserFontChanged&gt;&gt;</B></A><DD>
Sent to the dialog parent whenever the font selection dialog is visible and the
selected font changes, both as a result of user action and of the <B>-font</B>
configuration option being set. Binding scripts can determine the currently
selected font by querying the <B>-font</B> configuration option.
<P></DL>
<P>
<H3><A NAME="M17">NOTES</A></H3>
Callers should not expect a result from <B><A HREF="../TkCmd/tk.htm">tk fontchooser</A></B> <B>show</B> and may
not assume that the dialog has been withdrawn or closed when the command
returns. All user interaction with the dialog is communicated to the caller via
the <B>-command</B> callback and the <B>&lt;&lt;TkFontchooser*&gt;&gt;</B> virtual events.
It is implementation dependent which exact user actions result in the callback
being called resp. the virtual events being sent. Where an Apply or OK button
is present in the dialog, that button will trigger the <B>-command</B> callback
and <B>&lt;&lt;TkFontchooserFontChanged&gt;&gt;</B> virtual event. On some implementations
other user actions may also have that effect; on Mac OS X for instance, the
standard font selection dialog immediately reflects all user choices to the
caller.
<P>
In the presence of multiple widgets intended to be influenced by the font
selection dialog, care needs to be taken to correctly handle focus changes: the
font selected in the dialog should always match the current font of the widget
with the focus, and the <B>-command</B> callback should only act on the widget
with the focus. The recommended practice is to set font dialog <B>-font</B> and
<B>-command</B> configuration options in per-widget <B>&lt;FocusIn&gt;</B> handlers
(and if necessary to unset them - i.e. set to the empty string - in
corresponding <B>&lt;FocusOut&gt;</B> handlers). This is particularly important for
implementers of library code using the font selection dialog, to avoid
conflicting with application code that may also want to use the dialog.
<P>
Because the font selection dialog is application-global, in the presence of
multiple interpreters calling <B><A HREF="../TkCmd/tk.htm">tk fontchooser</A></B>, only the <B>-command</B>
callback set by the interpreter that most recently called <B><A HREF="../TkCmd/tk.htm">tk fontchooser</A></B>
<B>configure</B> or <B><A HREF="../TkCmd/tk.htm">tk fontchooser</A></B> <B>show</B> will be invoked in response
to user action and only the <B>-parent</B> set by that interpreter will receive
<B>&lt;&lt;TkFontchooser*&gt;&gt;</B> virtual events.
<P>
The font dialog implementation may only store (and return) <B><A HREF="../TkCmd/font.htm">font</A></B>
<B>actual</B> data as the value of the <B>-font</B> configuration option. This
can be an issue when <B>-font</B> is set to a named font, if that font is
subsequently changed, the font dialog <B>-font</B> option needs to be set again
to ensure its selected font matches the new value of the named font.
<P>
<H3><A NAME="M18">EXAMPLE</A></H3>
<PRE>proc fontchooserDemo {} {
    wm title . &quot;Font Chooser Demo&quot;
    <B><A HREF="../TkCmd/tk.htm">tk fontchooser</A></B> <B>configure</B> -parent .
    button .b -command fontchooserToggle -takefocus 0
    fontchooserVisibility .b
    bind . <B>&lt;&lt;TkFontchooserVisibility&gt;&gt;</B> &#92;
            [list fontchooserVisibility .b]
    foreach w {.t1 .t2} {
        text $w -width 20 -height 4 -borderwidth 1 -relief solid
        bind $w &lt;FocusIn&gt; [list fontchooserFocus $w]
        $w insert end &quot;Text Widget $w&quot;
    }
    .t1 configure -font {Courier 14}
    .t2 configure -font {Times 16}
    pack .b .t1 .t2; focus .t1
}
proc fontchooserToggle {} {
    <B><A HREF="../TkCmd/tk.htm">tk fontchooser</A></B> [expr {
            [<B><A HREF="../TkCmd/tk.htm">tk fontchooser</A></B> <B>configure</B> -visible] ?
            &quot;<B>hide</B>&quot; : &quot;<B>show</B>&quot;}]
}
proc fontchooserVisibility {w} {
    $w configure -text [expr {
            [<B><A HREF="../TkCmd/tk.htm">tk fontchooser</A></B> <B>configure</B> -visible] ?
            &quot;Hide Font Dialog&quot; : &quot;Show Font Dialog&quot;}]
}
proc fontchooserFocus {w} {
    <B><A HREF="../TkCmd/tk.htm">tk fontchooser</A></B> <B>configure</B> -font [$w cget -font] &#92;
            -command [list fontchooserFontSelection $w]
}
proc fontchooserFontSelection {w font args} {
    $w configure -font [font actual $font]
}
fontchooserDemo</PRE>
<H3><A NAME="M19">SEE ALSO</A></H3>
<B><A HREF="../TkCmd/font.htm">font</A></B>, <B><A HREF="../TkCmd/tk.htm">tk</A></B>
<H3><A NAME="M20">KEYWORDS</A></H3>
<A href="../Keywords/D.htm#dialog">dialog</A>, <A href="../Keywords/F.htm#font">font</A>, <A href="../Keywords/F.htm#font selection">font selection</A>, <A href="../Keywords/F.htm#font chooser">font chooser</A>, <A href="../Keywords/F.htm#font panel">font panel</A>
<div class="copy">Copyright &copy; 2008 Daniel A. Steffen &lt;das(at)users.sourceforge.net&gt;
</div>
</BODY></HTML>
